<!-- 

BASIL - FINISH BAG THING N PUT IN HERE. 
	  

DANIEL - LABLES, TITLES AND SHEEIT FOR HEBBUDDY AND BIGBUSINESS COMPARISON
       DAY OF THE WEEK
       CALENDAR
       
       
       
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title>jQuery Timeline 0.9.4 - Dando vida al tiempo</title>
	<link rel="stylesheet" href="jquery/jquerytime/css/style.css" type="text/css" media="screen" />
	
	<script src="jquery/jquery-1.6.4.js" type="text/javascript"></script>
	<script src="jquery/jquerytime/js/jquery.timelinr-0.9.4.js" type="text/javascript"></script>
	<script type="text/javascript"> 
	var xmlDocDates;
	var xmlDocDetails;
	var myTest = '';
	$(function(){
		xmlDocDates = makeRequest("orderDates");
		if(xmlDocDates == -1){
			alert("Query error\n");
		}
		var count = 0;
		var myStr = '';
		while(xmlDocDates.getElementsByTagName("DateGroup")[count] != undefined){
			var currID = xmlDocDates.getElementsByTagName("DateGroup")[count].childNodes[0].childNodes[0].nodeValue;
			myStr = myStr + '<option value="' + count + '">' + currID + '</option>'
			count++;
		}
		document.getElementById("custSelect").innerHTML = myStr;
		
		updateTimeline();
	});
	
	
	function makeRequest(str){
	
		//send request for given query
		url = "queries.php?string=" + str;
		if (window.XMLHttpRequest) { // Non-IE browsers 
			req = new XMLHttpRequest(); 
			req.str = str;
			try { 
				req.open("GET", url, false); 
			} catch (e) { 
				alert(e); 
			} 
			req.send(null); 
		} else if (window.ActiveXObject) { // IE 
		req = new ActiveXObject("Microsoft.XMLHTTP"); 
			if (req) { 
				req.open("GET", url, false); 
				req.send(); 
			} 
		}
		
		//parse response and return the XMLDoc
		var thisXMLDoc;
		if (req.status != 200){
			return -1;
		};
		
		myResponse = req.responseText;
		//console.log(myResponse);
		if (window.DOMParser)
		{
			parser=new DOMParser();
			thisXMLDoc=parser.parseFromString(myResponse,"text/xml");					
		}
		else // Internet Explorer
		{
			thisXMLDoc=new ActiveXObject("Microsoft.XMLDOM");
			thisXMLDoc.async="false";
			thisXMLDoc.loadXML(myResponse); 					
		}	
		return thisXMLDoc;			
	}	
	
	function updateTimeline(){
		var myStr = '';
		var count = 2;
		var selectIndex = document.getElementById("custSelect").value;
		var dateUL = document.getElementById("dates");
		while(xmlDocDates.getElementsByTagName("DateGroup")[selectIndex].childNodes[count] != undefined){
			//parse xml and retrieve order date
			var thisDate = xmlDocDates.getElementsByTagName("DateGroup")[selectIndex].childNodes[count].childNodes[0].nodeValue;
			//split and create proper tags for timeline string 'lineStr'
			var dateArray = thisDate.split("-");
			var year = dateArray[0];
			var month = dateArray[1];
			var day = dateArray[2];
			var dateStr = '';
			switch(month){
				case '01':dateStr = 'Jan';break;
				case '02':dateStr = 'Feb';break;
				case '03':dateStr = 'Mar';break;
				case '04':dateStr = 'Apr';break;
				case '05':dateStr = 'May';break;
				case '06':dateStr = 'Jun';break;
				case '07':dateStr = 'Jul';break;
				case '08':dateStr = 'Aug';break;
				case '09':dateStr = 'Sep';break;
				case '10':dateStr = 'Oct';break;
				case '11':dateStr = 'Nov';break;
				case '12':dateStr = 'Dec';break;
				default:dateStr = "ERROR";
			}
			dateStr = dateStr + ' ' + day;			
			var newDateA = document.createElement("a");
			newDateA.href = '#' + dateStr;
			newDateA.innerHTML = dateStr;
			var newDateLI = document.createElement("LI");
			newDateLI.appendChild(newDateA);
			dateUL.appendChild(newDateLI);	
			
			
			xmlDocDetails = makeRequest("orderDetailInfoPerDay&date=" + thisDate + "&selectIndex="  + selectIndex);
			
			if(xmlDocDetails != -1){
				var ctHEB = 0;
				var ctBigBus = 0;
				var detCount = 2;
				var totalProd = 0;
				var detailString = '';
				var Savings = 0;
				while(xmlDocDetails.getElementsByTagName("DetailsGroup")[selectIndex].childNodes[detCount] != undefined){
					
					var isHEB = xmlDocDetails.getElementsByTagName("DetailsGroup")[selectIndex].childNodes[detCount].childNodes[6].childNodes[0];
					console.log(isHEB.data);
					if(isHEB.data == "Y"){
						ctHEB++;
					} else {
						ctBigBus++;
					}
					var priceOfProd = xmlDocDetails.getElementsByTagName("DetailsGroup")[selectIndex].childNodes[detCount].childNodes[2].childNodes[0];
					var saveOnProd = xmlDocDetails.getElementsByTagName("DetailsGroup")[selectIndex].childNodes[detCount].childNodes[3].childNodes[0];
					
					//console.log(xmlDocDetails.getElementsByTagName("DetailsGroup")[selectIndex].childNodes[detCount].childNodes[7].childNodes[0]);
					totalProd++;
					detCount++;
				}
		
				
				
				
				var totalProducts = ctHEB + ctBigBus;
				var HEBRatio = ctHEB/totalProd;
				var BigBusRatio = ctBigBus/totalProd;
				
				var issueUL = document.getElementById("issues");
				var newIssueLI = document.createElement("LI");
				newIssueLI.id = dateStr;
				
				var newIssueImgBuddy = document.createElement("img");
				newIssueImgBuddy.src = "img/hebuddy.gif";
				if(HEBRatio == 0){
				newIssueImgBuddy.width=256*0.1;
				newIssueImgBuddy.height=256*0.1;
				value = 50;
				newIssueImgBuddy.style.opacity = value/10;
				newIssueImgBuddy.style.filter = 'alpha(opacity=' + value*10 + ')';
				} else {
				newIssueImgBuddy.width=256*HEBRatio;
				newIssueImgBuddy.height=256*HEBRatio;
				}
				
				var newIssueImgBigBus = document.createElement("img");
				newIssueImgBigBus.src = "img/greed.gif";
				if(BigBusRatio == 0){
				newIssueImgBigBus.width=256*BigBusRatio;
				newIssueImgBigBus.height=256*BigBusRatio;
				} else {
				newIssueImgBigBus.width=256*(0.1);
				newIssueImgBigBus.height=256*(0.1);
				}
				
				var newIssueP = document.createElement("P");
				newIssueP.id = dateStr;
				newIssueP.innerHTML = ctHEB + "STFF";
				
				var newIssueP = document.createElement("P");
				newIssueP.id = dateStr;
				newIssueP.innerHTML = ctHEB + "STFF";
				
				newIssueLI.appendChild(newIssueImgBuddy);
				newIssueLI.appendChild(newIssueImgBigBus);
				newIssueLI.appendChild(newIssueP);
				issueUL.appendChild(newIssueLI);	
				
				//console.log(xmlDocDetails.getElementsByTagName("DetailsGroup")[selectIndex].childNodes[2].childNodes[7].childNodes[0]);
				//console.log(ctHEB);
				//console.log(ctBigBus);
				//console.log(productRatio);
			}
			

			count++;
		}
		$().timelinr()
	}
	</script>
</head>

<body>

	<a href="javascript:processAjax('foo');">CLICK ME</a> 
	<div id="Return"></div> 
	<br />
	
	<div>
		<select id="custSelect" onchange="javascript:updateTimeline();">
		</select>
	</div>
	
	<div id="timeline">
		<ul id="dates">
		</ul>
		<ul id="issues">
		
		</ul>
		<div id="grad_left"></div>
		<div id="grad_right"></div>
		<a href="#" id="next">+</a>
		<a href="#" id="prev">-</a>
	</div>
	
</body>
</html>
